package eight;

import java.util.Map;
import java.util.TreeMap;

public class 八九TreeMap {
    public static void main(String[] args) {
        Emp emp1 = new Emp(5, "tom", 2000);
        Emp emp2 = new Emp(3, "jim", 4000);
        Emp emp3 = new Emp(7, "gem", 3000);
        Emp emp4 = new Emp(6, "hem", 3000);
        Map<Emp, String> map = new TreeMap<Emp, String>(){{
            put(emp1, "A");
            put(emp2, "A");
            put(emp3, "A");
            put(emp4, "A");
            put(emp1, "A");
        }};
        for (Emp emp : map.keySet()) {
            System.out.println(emp);
        }
        System.out.println(map);
    }
}

@SuppressWarnings("all")
class Emp implements Comparable<Emp>{
    private int id;
    private String name;
    private double salary;

    public Emp(int id, String name, double salary) {
        this.id = id;
        this.name = name;
        this.salary = salary;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    @Override
    public String toString() {
        return "Emp{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", salary=" + salary +
                '}';
    }

    @Override
    public int compareTo(Emp o) {
        if (this.salary > o.salary) {
            return 1;
        } else if (this.salary < o.salary) {
            return -1;
        } else {
            if (this.id > o.id) {
                return 1;
            } else if (this.id < o.id) {
                return -1;
            }else{
                return 0;
            }
        }
    }
}
